package sys.market.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import sys.charts.BarChart;
import sys.market.page.model.AdmissionRecord;
import sys.market.page.model.DataGrid;
import sys.market.page.model.Json;
import sys.market.service.AdmissionRecordService;

import com.opensymphony.xwork2.ModelDriven;
@ParentPackage("default")
@Namespace("/market/rygz")
@Action(value="admissionRecAction")
@Results(value={
		@Result(name="importFromHis",location="/market/rygz/hisinfo.jsp"),
		@Result(name="list",location="/market/rygz/show.jsp"),
		@Result(name="detail",location="/market/rygz/detail.jsp"),
		@Result(name="loadFromHis",location="/market/rygz/add.jsp"),
		@Result(name="scbjx",location="/market/rygz/scbjx.jsp"),
		@Result(name="ysfd",location="/market/rygz/ysfd.jsp"),
		@Result(name="brfy",location="/market/rygz/brfy.jsp")
	})
public class AdmissionRecAction extends BaseAction  implements ModelDriven<AdmissionRecord>{
	AdmissionRecord admissionRec = new AdmissionRecord();
	private AdmissionRecordService admissionRecService;
	@Override
	public AdmissionRecord getModel() {
		// TODO Auto-generated method stub
		return admissionRec;
	}
	
	public AdmissionRecordService getAdmissionRecService() {
		return admissionRecService;
	}
	@Autowired
	public void setAdmissionRecService(AdmissionRecordService admissionRecService) {
		this.admissionRecService = admissionRecService;
	}

	public String importFromHis() {
		DataGrid grid = null;
		if (admissionRec.getPageSize() == 0) {
			admissionRec.setPageSize(10);
		}
		if (admissionRec.getPageCurrent()==0) {
			admissionRec.setPageCurrent(1);
		}
		try {
			grid = admissionRecService.importFromHis(admissionRec);
		} catch (Exception ex) {
			//ex.printStackTrace();
		}
		super.setAttribute("recList", grid);
		super.setAttribute("admissionRec", admissionRec);
		return "importFromHis";
	}
	public String loadFromHis() {
		AdmissionRecord admissRec = null;
		admissRec = admissionRecService.loadFromHis(admissionRec); 
		super.setAttribute("admissRec", admissRec);
		return "loadFromHis";
	}
	public void add() {
		Json json = new Json();
		try {
			admissionRecService.add(admissionRec);
		} catch(Exception ex) {
			json.setSuccess(false);
			json.setMsg("保存出错");
		}
		json.setSuccess(true);
		json.setMsg("保存成功");
		super.writeJson(json);
	}
	public void checklrbz() {
		Json json = new Json();
		boolean result = false;
		try {
			result = admissionRecService.checklrbz(admissionRec.getZdh());
		} catch(Exception ex) {
			json.setSuccess(false);
			json.setMsg(ex.getMessage());
			json.setResult(result);
		}
		json.setSuccess(true);
		json.setResult(result);
		super.writeJson(json);
	}
	public String list() {
		DataGrid grid = null;
		if (admissionRec.getPageSize() == 0) {
			admissionRec.setPageSize(10);
		}
		if (admissionRec.getPageCurrent()==0) {
			admissionRec.setPageCurrent(1);
		}
		try {
			grid = admissionRecService.list(admissionRec);
		} catch (Exception ex) {
			//ex.printStackTrace();
		}
		try {
		} catch (Exception e) {
			
		}
		super.setAttribute("rydList", grid);
		super.setAttribute("admissionRec", admissionRec);
		return "list";
	}
	public String detail() {
		AdmissionRecord rec = null;
		try {
			rec = admissionRecService.detail(admissionRec);
		} catch(Exception ex) {
			ex.printStackTrace();
		}
		super.setAttribute("admissionRec", rec);
		return "detail";
	}
	public void edit() {
		Json json = new Json();
		boolean result = false;
		try {
			admissionRecService.update(admissionRec);	
		} catch(Exception ex) {
			json.setSuccess(false);
			json.setMsg(ex.getMessage());
			json.setResult(result);
		}
		json.setSuccess(true);
		json.setResult(result);
		super.writeJson(json);
	}
	public void ryrcByfb() {
		Json json = new Json();
		boolean result = false;
		BarChart bar = null;
		try {
			bar = admissionRecService.rytj(admissionRec);	
		} catch(Exception ex) {
			json.setSuccess(false);
			json.setMsg(ex.getMessage());
			json.setResult(result);
		}
		json.setSuccess(true);
		json.setResult(bar);
		super.writeJson(json);
	}
	public String scbjx() {
		DataGrid grid = null;
		try {
			grid = admissionRecService.scbjx(admissionRec);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		super.setAttribute("prizeList", grid);
		super.setAttribute("admissionRec", admissionRec);
		return "scbjx";
	}
	public String ysfd() {
		DataGrid grid = null;
		try {
			grid = admissionRecService.ysfd(admissionRec);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		super.setAttribute("ysfdList", grid);
		super.setAttribute("admissionRec", admissionRec);
		return "ysfd";
	}
	public String brfy() {
		DataGrid grid = null;
		try {
			grid = admissionRecService.brfy(admissionRec);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		super.setAttribute("brfyList", grid);
		super.setAttribute("admissionRec", admissionRec);
		return "brfy";
	}
}
